package com.magnificent.atlantis.client.data.message.messages;

import com.magnificent.atlantis.client.data.configuration.ServerConfiguration;
import com.magnificent.atlantis.common.entity.messages.ServerMessage;
import com.magnificent.atlantis.common.entity.messages.ServerTextMessage;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;

/**
 * User: Babanin
 * Date: 08.04.2009
 * Time: 14:03:32
 */
@XmlRootElement(name = "textMessage")
public class ClientTextMessage extends ClientMessage {

    private String title;
    private String message;

    private boolean read;
    protected Date date;

    public ClientTextMessage() {
    }

    public ClientTextMessage(ServerTextMessage serverTextMessage, ServerConfiguration configuration) {
        super(serverTextMessage, configuration);

        this.title = serverTextMessage.getTitle();
        this.message = serverTextMessage.getMessage();
        this.read = false;
    }

    @XmlAttribute()
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @XmlElement()
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @XmlAttribute()
    public boolean isRead() {
        return read;
    }

    public void setRead(boolean read) {
        this.read = read;
    }

    public boolean isSystemMessage() {
        return false;
    }

    public ServerMessage toServerMessage() {
        ServerTextMessage serverMessage = new ServerTextMessage();

        serverMessage.setTitle(title);
        serverMessage.setMessage(message);
        serverMessage.setSentDate(new Date());
        serverMessage.setUserFromId(userFromId);

        return serverMessage;
    }

    @XmlAttribute()
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}
